package com.msmap.apphome;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

/**
 * 网络的注册
 * Created by Administrator on 2016/10/22.
 */

public class NetWorkReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
            ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo info = manager.getActiveNetworkInfo();
            //获取连接的网络的类型名字
            String typeName = info.getTypeName();
            //获取网络类型
            int type = info.getType();
            switch (type) {
                case ConnectivityManager.TYPE_BLUETOOTH:
                    Toast.makeText(context, "蓝牙" + typeName, Toast.LENGTH_SHORT).show();
                    break;
                case ConnectivityManager.TYPE_MOBILE:
                    Toast.makeText(context, "手机:" + typeName, Toast.LENGTH_SHORT).show();
                    break;
                case ConnectivityManager.TYPE_WIFI:
                    Toast.makeText(context, "wifi:" + typeName, Toast.LENGTH_SHORT).show();
                    break;
            }

        }
    }
}
